package cn.school.student.common.converter;

import cn.school.student.common.enumdir.IsAlienEnum;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class IsAlienConverter implements Converter<Integer> {

    //java中的类型
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }
    //excel中的类型
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    //excel转java类型
    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String cellDataValue=cellData.getStringValue();
        Integer value= IsAlienEnum.getByLabel(cellDataValue).getValue();
        if(value==null){
            throw new Exception("是否为港澳台侨外输入不正确");
        }
        return value;
    }
    //java属性转excel
    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

}
